using System;
using System.Data;
using GameFramework.DataTable;
using GameFramework.Event;
using GameFramework.Procedure;
using UnityGameFramework.Runtime;
using ProcedureOwner = GameFramework.Fsm.IFsm<GameFramework.Procedure.IProcedureManager>;

public class Demo5_ProcedureLaunch : ProcedureBase
{
    //加载配置文件的核心步骤只有4个：

    // a.创建配置文件

    // b.创建文件类

    // c.加载配置文件到内存

    // d.在需要的地方读取配置文件内容     
    protected override void OnEnter(ProcedureOwner procedureOwner)
    {
        base.OnEnter(procedureOwner);

        GameEntry.Event.Subscribe(LoadDataTableSuccessEventArgs.EventId, OnLoadDataTableSuccess);
        //加载配置表
        DataTableBase dataTableBase = GameEntry.DataTable.CreateDataTable(Type.GetType("DRHero"));
        dataTableBase.ReadData("Assets/Data/DataTable/Hero.txt");
    }

    private void OnLoadDataTableSuccess(object sender, GameEventArgs e)
    {
        //获取表数据
        IDataTable<DRHero> dtScene = GameEntry.DataTable.GetDataTable<DRHero>();
        //获取所有行
        DRHero[] drHeroes = dtScene.GetAllDataRows();
        Log.Debug($"drHeros:{drHeroes.Length}");
        //根据行号获取某一行
        DRHero dRHero = dtScene.GetDataRow(1);
        if (dRHero != null)
        {
            Log.Debug($"name:{dRHero.Name}  atk:{dRHero.Atk}");
        }
        else
        {
            Log.Debug("此行不存在");
        }
        //获得满足条件的所有行DRHero[] drScenesWithCondition = dtScene.GetAllDataRows(x => x.Id > 0);更换为
        DRHero[] drScenesWithCondition = dtScene.GetDataRows(x => x.Id > 0);
        dtScene.GetDataRow(x => x.Name == "张三");

    }
}
